$(function() {
	$(window).bind('resize.Menu', function(e) {
		adjustImageSize($("#background"));
	});
	adjustImageSize($("#background"));
});

function adjustImageSize(images) {
	var w_w = $("body").width();
	var w_h = $("body").height()-157;

	var content = $('.vertical_align');
	//content.css('width', w_w + 'px');
	
	/*var contentChildren = content.children();
	var maxHeight = 0;
	
	contentChildren.each(function(){
		if ($(this).height() >= maxHeight)
			maxHeight = $(this).height();
	})
	
	content.css('height', 'auto');
	if (maxHeight <= content.height())*/
	content.css('height', w_h-34 + 'px');
	
	
	images.each(function() {
		var $img = $(this);
		var r_w = w_h / w_w, i_w = $img.width(), i_h = $img.height(), r_i = i_h
				/ i_w, new_w, new_h, new_left, new_top;

		var proportion = $img.is('[proportion]') ? $img.attr('proportion') : 1;

		if (r_w > r_i) {
			new_h = w_h / proportion;
			new_w = (w_h / proportion) / r_i;
		} else {
			new_h = (w_w / proportion) * r_i;
			new_w = w_w / proportion;
		}

		$img.css({
			width : new_w + 'px',
			height : new_h + 'px',
			left : (w_w - new_w) / 2 + 'px',
			top : (w_h - new_h) / 2 + 'px'
		});

	})
}
